#include "common/unp.h"

int main()
{
	int remotesock;
	struct sockaddr_in remoteaddr;
	if(( remotesock = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 ){
		perror(" socket() fail \n");
	}
	memset( &remoteaddr, 0, sizeof(remoteaddr) );
	remoteaddr.sin_family = AF_INET;
	remoteaddr.sin_port = htons( 4321 );
	remoteaddr.sin_addr.s_addr = htonl( INADDR_ANY );
	
	if( connect( remotesock,(struct sockaddr *) &remoteaddr, sizeof( remoteaddr ) ) < 0 ){
		perror(" connect() fail \n ");
	}
	char buf[1024];
	memset( buf, 0 , sizeof( buf ) );
	while( 1 ){
		scanf( "%s", buf );
		write( remotesock, buf, strlen( buf ) );
		int recvnum = read( remotesock, buf, 1024 );
		if( recvnum < 0 ){
			perror( "read() fail \n");
		}
		buf[recvnum] = '\0';
		printf( "%s", buf);

	}
	return 0;
}
